package com.a2020111222.test.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2022/11/13 22:53
 */
@Aspect
public class annoAdvice {
    @Pointcut("execution(* com.a2020111222.test.dao.impl.userNotesDaoImpl.*(..))")
    public void pointcut(){}

    /**
     * @description:  前置通知
     * @param: [joinPoint]
     * @return: void
     * @author Yang
     * @date: 2022/11/13 16:20
     */
    @Before("pointcut()")
    public void before(JoinPoint joinPoint){
        System.out.println("前置通知");
        System.out.println("目标类："+joinPoint.getTarget());
        System.out.println("被植入的增强方法："+joinPoint.getSignature().getName());
    }
    /**
     * @description:  返回通知
     * @param: [joinPoint]
     * @return: void
     * @author Yang
     * @date: 2022/11/13 16:22
     */
    @AfterReturning("pointcut()")
    public void afterReturning(JoinPoint joinPoint){
        System.out.println("返回通知（正常调用）");
        System.out.println("被植入的增强方法："+joinPoint.getSignature().getName());
    }

    /**
     * @description:  环绕通知
     * @param:  [ProceedingJoinPoint]
     * @return:  Object
     * @author Yang
     * @date: 2022/11/13 16:22
     */
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("环绕通知之前");
        Object obj =point.proceed();
        System.out.println("环绕通知之后");
        return obj;
    }

    /**
     * @description:  异常通知
     * @param: []
     * @return: void
     * @author Yang
     * @date: 2022/11/13 16:30
     */
    @AfterThrowing("pointcut()")
    public void afterException(){
        System.out.println("异常");
    }

    /**
     * @description:  后置通知
     * @param: []
     * @return: void
     * @author Yang
     * @date: 2022/11/13 16:30
     */
    @After("pointcut()")
    public void after(){
        System.out.println("后置通知");
    }
}
